<?php
// +----------------------------------------------------------------------
// |
// +----------------------------------------------------------------------
// |
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// |
// +----------------------------------------------------------------------

namespace app\model;

use think\Model;

class Order extends Model
{
	protected $name               = 'order';
	protected $autoWriteTimestamp = true;
	protected $insert             = [];
	protected $update             = [];

	const BRAND_ID_WECHAT = 0; // 微信小店品牌id

	const STATUS_WAIT          = 10; // 待付款
	const STATUS_GIFT_WAIT     = 12; // 待收礼
	const STATUS_DELIVERY_WAIT = 20; // 待发货
	const STATUS_DELIVERY_PART = 21; // 部分发货
	const STATUS_RECEIVE_WAIT  = 30; // 待收货
	const STATUS_COMPLETE      = 100; // 已完成
	const STATUS_CANCEL        = 200; // 全部商品售后之后，订单取消
	const STATUS_AUTO_CANCEL   = 250; // 未付款用户主动取消或超时未付款订单自动取消

	const COMMISSION_STATUS_WAIT     = 20; // 未结算
	const COMMISSION_STATUS_COMPLETE = 100; // 已结算
	const COMMISSION_STATUS_CANCEL   = 200; // 取消结算


	// 订单未结束状态
	public static array $statusWait = [
		self::STATUS_WAIT,
		self::STATUS_GIFT_WAIT,
		self::STATUS_DELIVERY_WAIT,
		self::STATUS_DELIVERY_PART,
		self::STATUS_RECEIVE_WAIT,
	];

	public function getCreateTimeAttr($value)
	{
		return $value ? date('Y-m-d H:i:s', $value) : '';
	}

	public function user()
	{
		return $this->belongsTo('User', 'user_id')
			->bind([
				'nickname' => 'nickname',
			]);
	}

	public function goods()
	{
		return $this->belongsTo(Goods::class, 'product_id')
			->bind([
				'sale_price' => 'sale_price',
				'image'      => 'image',
			]);
	}


}
